<?php
declare(strict_types=1);

/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/30
 * Time: 17:32
 */

namespace App\Job;

use App\Model\Notify;
use App\Model\User;
use Hyperf\AsyncQueue\Job;

class PushActJob extends Job
{
    public array $params;

    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     */
    protected int $maxAttempts = 2;
    protected object $act;

    public function __construct($params)
    {
        // 这里最好是普通数据，不要使用携带 IO 的对象，比如 PDO 对象
        $this->params = $params;
    }

    public function handle()
    {
        // 根据参数处理具体逻辑
        // 通过具体参数获取模型等
        // 这里的逻辑会在 ConsumerProcess 进程中执行
//        var_dump($this->params);
        if(!isset($this->params['id']) | $this->params['id']==null) return;
        //获取所有用户
        $userList = User::where('status',1)->whereNotNull('auth_time')->selectRaw('id,party_id')->get();
        if($userList->isNotEmpty()){
            foreach ($userList as $item) {
                $newsData['module'] = 3; //在线活动模块
                $newsData['party_id'] = $item->party_id;
                $newsData['relation_id'] = $this->params['id'];
                $newsData['uid'] = $item->id;
                $newsData['status'] = 1;
                Notify::create($newsData);
            }
        }
    }
}